package control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import swimv2.ejb.util.LoginToken;
import util.HtmlUtil;

/**
 * Servlet implementation class HomeAdmin
 */
public class HomeAdmin extends Servlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see Servlet#Servlet()
     */
    public HomeAdmin() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		PrintWriter out = response.getWriter();
		request.setAttribute("titolo", "Home Admin");
		HtmlUtil.inviaHeader(request, response);

		LoginToken tok = (LoginToken) request.getSession().getAttribute(
				"LoginToken");
		if (tok == null || !tok.isAmministratore()) {
			HtmlUtil.inviaIntestazioneVisitatore(request, response);
			HtmlUtil.redirect(request, response, "/");
		} else {
			String azione = (String) request.getParameter("azione");
			HtmlUtil.inviaIntestazioneAmministratore(request, response);
			if (azione != null && azione.equals("home")) {
				HtmlUtil.includi(request, response,
						"/WEB-INF/pages/homeAdmin.jsp?from=home");

				HtmlUtil.inviaFooter(request, response);
			} else if (azione != null && azione.equals("logOk")) {
				HtmlUtil.includi(request, response,
						"/WEB-INF/pages/homeAdmin.jsp?from=login");

			}
			HtmlUtil.inviaFooter(request, response);

		}

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
